package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜品相关接口")
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    DishService dishService;
    @ApiOperation("新增菜品接口")
    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO){

        dishService.saveWithFlavors(dishDTO);
        return Result.success();
    }

    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO){

        PageResult result = dishService.pageQuery(dishPageQueryDTO);

        return Result.success(result);
    }

    @ApiOperation("id查询菜品")
    @GetMapping("/{id}")
    public Result<DishVO>  getById(@PathVariable Long id){
        DishVO dish = dishService.getById(id);
        return Result.success(dish);
    }

    /**
     * 菜品批量删除
     * @param ids
     * @return
     */
    @ApiOperation("菜品批量删除")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        dishService.batchDelete(ids);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result update(@RequestBody  DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }

    @ApiOperation("菜品停售和启售")
    @PostMapping("/status/{status}")
    public Result saleAndHaltSale(Long id,@PathVariable  Integer status){
        dishService.saleAndHaltSale(id, status);
        return Result.success();
    }

    @ApiOperation("通过分类Id查找菜品")
    @GetMapping("/list")
    public Result<List<Dish>> getListByCategoryId(Long categoryId){
       List<Dish> dishList = dishService.getListByCategoryId(categoryId);
        return Result.success(dishList);
    }
}
